<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<!-- 导入jquery核心类库 -->
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<!-- 导入easyui类库 -->
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/ext/portal.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/css/default.css">	
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.portal.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.cookie.js"></script>
<script
	src="${pageContext.request.contextPath }/js/easyui/locale/easyui-lang-zh_CN.js"
	type="text/javascript"></script>
<script type="text/javascript">
	function doAdd(){
		//alert("增加...");
		$('#addUserWindow').window("open");
	}
	
	function doView(){
		var rows = $("#grid").datagrid('getSelections');
		if(rows.length == 1){
			//alert(rows[0].factoryId);
			$.post('/findNameShort.action',{id:rows[0].factoryId},function(data){
				
				alert(data.nameShort)
			},'json');
		}else{
			$.messager.alert('提示信息','一次只能选择一个员工','warning');
		}
		
	}
	///
	function doDelete(){
		var rows = $("#grid").datagrid('getSelections');
		if(rows.length<1){
			$.messager.alert('提示信息','请选择需要操作的员工！','warning');  
		}else{
			$.messager.confirm('提示信息', '您选择的员工确认办理<font color="red">离职</font>吗？', function(r){
				if (r){  
					var arr = new Array();
					for (var i = 0; i < rows.length; i++) {
						arr.push(rows[i].id);
					}
					var ids= arr.join(",");
					location.href="/checkUserType.action?ids="+ids;
				} });  
		}
	}
	//修改
	function doEdit(){
		alert("修改...");
	}
	
	function doRestore(){
		alert("将取派员还原...");
	}
	//工具栏
	var toolbar = [ {
		id : 'button-view',	
		text : '查询关联企业信息',
		iconCls : 'icon-search',
		handler : doView
	}, {
		id : 'button-add',
		text : '增加',
		iconCls : 'icon-add',
		handler : doAdd
	}, {
		id : 'button-delete',
		text : '离职',
		iconCls : 'icon-cancel',
		handler : doDelete
	}, {
		id : 'button-delete',
		text : '修改',
		iconCls : 'icon-edit',
		handler : doEdit
	},{
		id : 'button-save',
		text : '还原',
		iconCls : 'icon-save',
		handler : doRestore
	}];
	// 定义列
	var columns = [ [ {
		field : 'id',
		checkbox : true,
	},{
		field : 'name',
		title : '姓名',
		width : 120,
		align : 'center'
	}, {
		field : 'telephone',
		title : '手机号',
		width : 120,
		align : 'center'
	}, {
		field : 'isleader',
		title : '员工/领导',
		width : 120,
		align : 'center',
		formatter : function(data,row, index){
			if(data=="0"){
				return "普通员工";
			}else if(data=="1"){
				return "管理员";
			}else{
				return "<span style='color:red;'>未填写</span>";
			}
		}
	}, {
		field : 'department',
		title : '部门',
		width : 120,
		align : 'center',
		formatter : function(data,row, index){
			if(data=="0"){
				
				//0:业务部 1：人力资源部 2：安置部3：财务部
				return "业务部"
			}else if(data=="1"){
				return "人力资源部";
			}else if(data=="2"){
				return "安置部";
			}else if(data=="3"){
				return "财务部";
			}else{
				return "<span style='color:red;'>未分配</span>";
			}
		}
	 }, {
		field : 'factoryId',
		title : '驻管企业', 
		width : 120,
		align : 'center',
		formatter : function(data,row, index){
			//alert(row.factory.nameShort);
			if(row.factory == null){
				return "<span style='color:red;'>暂无驻管企业</span>";
			}else{
				
				return row.factory.nameShort;
			}
		} 
	}, {
		field : 'createtime',
		title : '创建时间',
		width : 120,
		align : 'center',
		formatter : function(data,row, index){
			if(data==null){
				return "<span style='color:red;'>未填写</span>";
			}else{
				var date = new Date(data);  
				var yyyy= date.getFullYear();
				var mm =date.getMonth()+1;
				var d = date.getDate(); 
                return yyyy+"年"+mm+"月"+d+"日";
			} 
			
			
		} 
	}, {
		field : 'usertype',
		title : '人员状态',
		width : 200,
		align : 'center',
		formatter : function(data,row, index){
			if(data=="0"){
				return "离职"
			}else if(data=="1"){
				return "在职";
			}else{
				return "<span style='color:red;'>未填写</span>";
			}
		}
	} ] ];
	
	$(function(){
		// 先将body隐藏，再显示，不会出现页面刷新效果
		$("body").css({visibility:"visible"});
		
		// 取派员信息表格
		$('#grid').datagrid( {
			iconCls : 'icon-forward',
			fit : true,
			border : false,
			rownumbers : true,
			striped : true,
			pageList: [30,50,100],
			pagination : true,
			toolbar : toolbar,
			url : "/UserPageQuery.action",
			idField : 'id',
			columns : columns,
			onDblClickRow : doDblClickRow
		});
		
		// 添加取派员窗口
		$('#addUserWindow').window({
	        title: '添加用户信息',
	        width: 400,
	        modal: true,
	        shadow: true,
	        closed: true,
	        height: 430,
	        resizable:false
	    });
		
		// 修改取派员窗口
		$('#editUserWindow').window({
	        title: '修改用户信息',
	        width: 400,
	        modal: true,
	        shadow: true,
	        closed: true,
	        height: 430,
	        resizable:false
	    });
		
	});
	//双击表格
	function doDblClickRow(rowIndex, rowData){
		$('#editUserWindow').window("open");
		$('#editUserWindow').form('load',rowData);
	}
	
	//动态添加合作企业
	 $(function(){
		$.post('/selectFactory.action',{},function(data){
			for (var i = 0; i < data.length;i++) {
				$("#addFactoryID").append("<option value='"+data[i].id+"'>---"+data[i].nameShort+"---</option>");
			}
			
		},'json');
	}) 
	//动态修改合作企业
	 $(function(){
		$.post('/selectFactory.action',{},function(data){
			for (var i = 0; i < data.length;i++) {
				if(data[i].id ==$("#editFactoryID").val()){
					$("#editFactoryID").append("<option value='"+data[i].id+"' selected='selected'>---"+data[i].nameShort+"---</option>");
				}
				$("#editFactoryID").append("<option value='"+data[i].id+"'>---"+data[i].nameShort+"---</option>");
			}
			
		},'json');
	}) 
	
	//效验手机号码规则
	$(function(){
		var tel=/^1[3,4,5,7,8]\d{9}$/;
		//效验手机
		$.extend($.fn.validatebox.defaults.rules, { 
			telephone: { 
			validator: function(value,param){ 
				return tel.test(value); 
			}, 
			message: '手机号码输入格式不对！'
			} 

			});
		//效验密码
		//var repass=$("#");
		$.extend($.fn.validatebox.defaults.rules, { 
			checkPassword: { 
			validator: function(value,param){ 
				return value==$("#user_pass").val(); 
			}, 
			message: '两次密码输入不一致！'
			} 

			}); 
		
		//添加用户信息
		$(function(){
			$("#saveUserInfo").click(function(){
				
			var va = $("#addStaffForm").form("validate");
				if(va){
					$("#addUserInfoForm").submit();
					$("#addUserWindow").window("close");
				}
			});
		});
	});
</script>	
</head>
<body class="easyui-layout" style="visibility:hidden;">
	<div region="center" border="false">
    	<table id="grid"></table>
	</div>
	<div class="easyui-window" title="对员工进行添加" id="addUserWindow" collapsible="false" minimizable="false" maximizable="false" style="top:20px;left:200px">
		<div region="north" style="height:31px;overflow:hidden;" split="false" border="false" >
			<div class="datagrid-toolbar">
				<a id="saveUserInfo" icon="icon-save" href="#" class="easyui-linkbutton" plain="true" >保存</a>
				<script type="text/javascript">
					$(function(){
						$("#saveUserInfo").click(function(){
							
						var va = $("#addStaffForm").form("validate");
							if(va){
								$("#addUserInfoForm").submit();
								$("#addUserWindow").window("close");
								//window.location.reload(); 
							}
						});
					});
				</script>
			</div>
		</div>
		
		<div region="center" style="overflow:auto;padding:5px;" border="false">
			<form id="addUserInfoForm" action="/addUserInfo.action" method="post">
				<table class="table-edit" width="80%" align="center">
					<tr class="title">
						<td colspan="2">用户信息添加</td>
					</tr>
					<tr>
						<td>姓名</td>
						<td><input type="text" name="name" class="easyui-validatebox" required="true"/></td>
					</tr>
					<tr>
						<td>账号</td>
						<td><input type="text" name="username" class="easyui-validatebox" required="true"/></td>
					</tr>
					<tr>
						<td>密码</td>
						<td><input id="user_pass" type="password" name="password" class="easyui-validatebox" validType="length[4,10]" required="true"/></td>
					</tr>
					<tr>
						<td>确认密码</td>
						<td><input id="re_user_pass" type="password" class="easyui-validatebox" validType="checkPassword" required="true"/></td>
					</tr>
					<tr>
						<td>手机</td>
						
						<td><input id="user_tel" type="text" name="telephone" class="easyui-validatebox" validType="telephone" required="true"/></td>
					</tr>
					<tr>
						<td>是否领导</td>
						<td><select name="isleader">
								<option value="0">--普通员工--</option>
								<option value="1">--管理员--</option>
						</select></td>
					</tr>
					<tr>
						<td>部门</td>
						<td><select name="department">
								<option value="0">---业务部---</option>
								<option value="1">--人力资源部 --</option>
								<option value="2">---安置部 ---</option>
								<option value="3">---财务部 ---</option>
						</select></td>
					</tr>
					 <tr>
						<td>驻管企业</td>
						<td><select name="factoryId" id="addFactoryID">
								<option value="">----请选择----</option>
						</select></td>
					</tr>
					<tr>
						<td>人员状态</td>
						<td><select name="usertype">
								<option value="1">---在职 ---</option>
								<option value="0">---离职---</option>
						</select></td>
					</tr>
				</table>
			</form>
		</div>
	</div>
	
	<!-- 修改信息 -->
	<div class="easyui-window" title="对员工进行修改" id="editUserWindow" collapsible="false" minimizable="false" maximizable="false" style="top:20px;left:200px">
		<div region="north" style="height:31px;overflow:hidden;" split="false" border="false" >
			<div class="datagrid-toolbar">
				<a id="editUserInfo" icon="icon-save" href="#" class="easyui-linkbutton" plain="true" >保存</a>
				<script type="text/javascript">
					
				</script>
			</div>
		</div>
		
		<div region="center" style="overflow:auto;padding:5px;" border="false">
			<form id="addUserInfoForm" action="/addUserInfo.action" method="post">
				<input type="hidden" name="id"/>
				<table class="table-edit" width="80%" align="center">
					<tr class="title">
						<td colspan="2">用户信息修改</td>
					</tr>
					<tr>
						<td>姓名</td>
						<td><input type="text" name="name" class="easyui-validatebox" required="true"/></td>
					</tr>
					
					<tr>
						<td>手机</td>
						
						<td><input id="user_tel" type="text" name="telephone" class="easyui-validatebox" validType="telephone" required="true"/></td>
					</tr>
					<tr>
						<td>是否领导
							<script type="text/javascript">
								$(function(){
									if(){
										
									}
									
								})
						</script>
						</td>
						<td><select name="isleader">
							
								<option value="0" >--普通员工--</option>
								<option value="1" selected="selected">--管理员--</option>
						</select></td>
					</tr>
					<tr>
						<td>部门</td>
						<td><select name="department">
								<option value="0">---业务部---</option>
								<option value="1">--人力资源部 --</option>
								<option value="2">---安置部 ---</option>
								<option value="3">---财务部 ---</option>
						</select></td>
					</tr>
					<tr>
						<td>驻管企业</td>
						<td><select name="factoryId" id="editFactoryID">
								<option value="">----请选择----</option>
						</select></td>
					</tr>
					<tr>
						<td>人员状态</td>
						<td><select name="usertype">
								<option value="1">---在职 ---</option>
								<option value="0">---离职---</option>
						</select></td>
					</tr>
				</table>
			</form>
		</div>
	</div>
</body>
</html>	